package main

import (
	"fmt"
	"gitee.com/volvoxc60/go-crawler/engine"
	"gitee.com/volvoxc60/go-crawler/zhenai/parser"
	"io/ioutil"
	"net/http"
	"net/http/cookiejar"
	"net/url"
	"time"
)

const SeedUrl = "http://www.zhenai.com/zhenghun/"
const ProfileUrl = "https://album.zhenai.com/u/1722767695"

func main() {
	e := engine.Request{
		Url:       SeedUrl,
		ParseFunc: parser.ParseCityList,
	}
	engine.Run(e)

}

func withCookieYLY() {
	//Init jar
	j, _ := cookiejar.New(nil)
	// Create client
	client := &http.Client{Jar: j}
	// Create request
	req, err := http.NewRequest("GET", "https://yilianyun.10ss.net/device/index?dev=4004736520", nil)
	// Fetch Request
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Failure : ", err)
	}
	//开始修改缓存jar里面的值
	var cookieList []*http.Cookie
	cookieList = append(cookieList, &http.Cookie{
		Name:    "BMAP_SECKEY2",
		Domain:  "yilianyun.10ss.net",
		Path:    "/",
		Value:   "BMAP_SECKEY2=646f10cb77181888e7eef50bc07d45274c5fe0c85c4ae6a2b8a66de6bcc21f3371287d727a5322140481ce64c70ad1b657a6e09c31496fd4129b0c48c0873df51c1493b0870c4ae16f0f98e4c8f9aa7c716e6f32f0fb3f4ae40e6dd5b7a990a5c53cde6def8f047d4a1dde68098b2c72d9d3a0fbb66b3f324b57f37526b5f41efbc4bfd9fe80e9ed871233174c86656709f1831b9b6998883766efc60418ddc32fd243f3dfb43f9a2487f3354641c2ddefdd11edf14bf15de276528d16b98a34f6d7d6a1c3d99ab393b994129a20f9ee311dfb05b8ce0e0feb968e1ef9b5e1587d0915a1906f12d2b1b0721a27cdc0ba",
		Expires: time.Now().AddDate(1, 0, 0),
	})
	cookieList = append(cookieList, &http.Cookie{
		Name:    "_csrf",
		Domain:  "yilianyun.10ss.net",
		Path:    "/",
		Value:   "93936255e2f90ad2ad52c78091f4a32007cec1080d629874f21514352ec1d8eda%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22v%E4%C5%09Vd%F8%A2%26%C4%F9%27%C8%8A%B8%27%16%13%EA%A2%3D%EFLI%98%905c%8A%BAf%BF%22%3B%7D",
		Expires: time.Now().AddDate(1, 0, 0),
	})
	cookieList = append(cookieList, &http.Cookie{
		Name:    "PHPSESSID",
		Domain:  "yilianyun.10ss.net",
		Path:    "/",
		Value:   "6bef78691e64d8415dc1ea34",
		Expires: time.Now().AddDate(1, 0, 0),
	})
	cookieList = append(cookieList, &http.Cookie{
		Name:    "pageNo",
		Domain:  "yilianyun.10ss.net",
		Path:    "/",
		Value:   "1",
		Expires: time.Now().AddDate(1, 0, 0),
	})
	cookieList = append(cookieList, &http.Cookie{
		Name:    "UM_distinctid",
		Domain:  "yilianyun.10ss.net",
		Path:    "/",
		Value:   "17a7b244d21b79-0cfdd508785c2e-34647600-1fa400-17a7b244d22520",
		Expires: time.Now().AddDate(1, 0, 0),
	})
	urlX, _ := url.Parse("https://yilianyun.10ss.net/device/index?dev=4004736520")
	j.SetCookies(urlX, cookieList)

	fmt.Printf("Jar cookie : %v", j.Cookies(urlX))
	// Fetch Request
	resp, err = client.Do(req)
	if err != nil {
		fmt.Println("Failure : ", err)
	}

	// Read Response Body
	respBody, _ := ioutil.ReadAll(resp.Body)

	// Display Results
	fmt.Println("response Status : ", resp.Status)
	fmt.Println("response Headers : ", resp.Header)
	fmt.Println("response Body : ", string(respBody))
	fmt.Printf("response Cookies :%v", resp.Cookies())
}
